<!DOCTYPE html>
<html>
  <head>

    <title>Layui</title>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css">
    <!-- <script src="js/jquery-1.4.1.min.js" type="text/javascript"></script> -->
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="js/audio.min.js"></script>
  </head>

  <body >
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
      <legend>mp3</legend>
    </fieldset>
    <audio src="js/juicy.mp3" id="vid1" preload="auto"></audio>

    <div class="layui-btn-container" id="content">
    </div>
    <script src="layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
  </body>

<script language="javascript" type="text/javascript">
  		function getQueryVariable(variable)
			{
       			var query = window.location.search.substring(1);
      			 var vars = query.split("&");
       			for (var i=0;i<vars.length;i++) {
               		var pair = vars[i].split("=");
               		if(pair[0] == variable){return pair[1];}
       			}
      			 return(false);
			}
      function clickBtn(a){
        var path =getQueryVariable("path");
        path=decodeURI(path);
        console.log("\\" + path + "\\"+a);
            // console.log(event);
            // console.log(a)
            var mp3Src ="\\" + path + "\\"+a;
            var player =document.getElementById('vid1');
          console.log(player);
          player.src=mp3Src;

        //playSound("\\" + path + "\\"+a);
      }

      function playSound(srcstr)
    {
      var borswer = window.navigator.userAgent.toLowerCase();
      if ( borswer.indexOf( "ie" ) >= 0 )
      {
        //IE内核浏览器
        var strEmbed = "<embed name='embedPlay' src='"+srcstr+"' autostart='true' hidden='true' loop='false'></embed>";
        if ( $( "body" ).find( "embed" ).length <= 0 )
          $( "body" ).append( strEmbed );
        var embed = document.embedPlay;

        //浏览器不支持 audion，则使用 embed 播放
        embed.volume = 100;
        //embed.play();这个不需要
      } else
      {
        //非IE内核浏览器
        var strAudio = "<audio id='audioPlay' src='"+srcstr+"' hidden='true'>";
        if ( $( "body" ).find( "audio" ).length <= 0 )
          $( "body" ).append( strAudio );
        var audio = document.getElementById( "audioPlay" );

        //浏览器支持 audion
        audio.play();
      }
    }
  $(function () {
    var path =getQueryVariable("path");
    path=decodeURI(path);
      var htmlobj = $.ajax({ url: "/" + path + "/info.txt", async: false });
      console.log("/" + path + "/info.txt");
      var v = htmlobj.responseText;
      var arrs = v.split("\r\n");
      console.log("数量："+arrs.length);
      for (var i = 0; i < arrs.length; i++) {
        if(arrs[i].includes("info.txt")||arrs[i].length==0||arrs[i].includes("a.bat")){
          console.log("空："+arrs[i]);
        }
        else if(path.includes("mp3")){    
          // var path2="\\" + path + "\\"+arrs[i];
          // console.log("png:"+path2);
          $("#content").append("<button onclick=\"clickBtn(\'" + arrs[i] + "\')\" class='layui-btn layui-btn-normal'>" + arrs[i] + "</button>");
        }
       else{
        var path2=arrs[i];
          console.log("other:"+path2);
        }
      }

  })

  audiojs.events.ready(function() {
      var as = audiojs.createAll();
    });
</script>

</html>